package cn.xie.blog.webadmin.web.service.impl;

import cn.xie.blog.commonutil.response.Response;
import cn.xie.blog.model.common.param.login.LoginParam;
import cn.xie.blog.model.common.param.registered.RegisteredParam;
import cn.xie.blog.model.common.vo.UserDetailsVO;
import cn.xie.blog.serverutil.constant.common.Responseconstant;
import cn.xie.blog.serverutil.exception.BlogException;
import cn.xie.blog.serviceuserclient.UserClient;
import cn.xie.blog.webadmin.web.service.UserWebService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: xiaoxie
 * create: 2025-04-26 12:31
 * @BelongsProject: blog-parent
 * @BelongsPackage: cn.xie.blog.webadmin.web.service
 * description:
 */
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserWebServiceImpl implements UserWebService {

    private static final Logger log = LoggerFactory.getLogger(UserWebServiceImpl.class);
    @Resource
    private UserClient userClient;
    @Override
    public String login(LoginParam loginParam) {
        Response<String> response = userClient.userLogin(loginParam);
        if (response.getCode() != Responseconstant.SUCCESS) {
            log.error("用户登录异常:{},username: {}", response.getMsg(), loginParam.getUsername());
            throw new BlogException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    @Override
    public UserDetailsVO getUserDetailsById(String userId) {
        return null;
    }

    @Override
    public Boolean logout() {
        Response<Boolean> response = userClient.logout();
        if (response.getCode() != Responseconstant.SUCCESS) {
            log.error("用户注销异常:{}", response.getMsg());
            throw new BlogException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
